package com.isunland.managesystem.ui;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.NavUtils;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.isunland.managesystem.R;
import com.isunland.managesystem.base.BaseVolleyActivity;
import com.isunland.managesystem.entity.DataStatus;
import com.isunland.managesystem.entity.MonthAttendanceOriginal;

/**
 * 对象功能:  月考请详情
 * 开发公司: 北京信普达系统工程有限公司
 * 开发人员: HuXiaoDan
 * 创建时间: 2016/5/9 16:45
 */
public class MonthAttendanceDetailFragment extends Fragment {
  public static final String EXTRA_VALUE =
      "com.isunland.managesystem.ui.MonthAttendanceDetailFragment.EXTRA_VALUE";
  private MonthAttendanceOriginal.MonthAttendanceContent content;

  private TextView tvAttendyearMonth;
  private TextView tvStaffName;
  private TextView tvNaturalDays;
  private TextView tvWorkDays;
  private TextView tvPaidSalaryDays;
  private TextView tvRebackDescribe;
  private TextView tvOnPositionDays;
  private TextView tvLunchFee;
  private TextView tvPrivateDays;
  private TextView tvOtherDays;
  private TextView tvMaternityLeaveDays;
  private TextView tvSickDays;
  private TextView tvPaidDays;
  private TextView tvLateTimes;
  private TextView tvEarlierTimes;
  private TextView tvPunitiveDays;
  private TextView tvExtraDays;
  private TextView tvExtraPayDays;
  private TextView tvStatutoryHoliday;
  private TextView tvDeductionDays;
  private TextView tvHandleDesc;
  private TextView tvDataStatuse;
  private TextView tvRegisterName;
  private TextView tvRegisterTime;
  private TextView tvCheckorName;
  private TextView tvCheckTime;
  private TextView tvApprManName;
  private TextView tvApprManTime;
  private TextView tvAbsenceDays;

  @Override public void onCreate(Bundle savedInstanceState) {
    setHasOptionsMenu(true);
    ((BaseVolleyActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    ((BaseVolleyActivity) getActivity()).getSupportActionBar()
        .setTitle(R.string.monthAttendanceDetail);
    content = (MonthAttendanceOriginal.MonthAttendanceContent) getArguments().getSerializable(
        EXTRA_VALUE);
    super.onCreate(savedInstanceState);
  }

  @Override public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case android.R.id.home:
        if (NavUtils.getParentActivityName(getActivity()) != null) {
          NavUtils.navigateUpFromSameTask(getActivity());
        }
        break;

      default:
        break;
    }
    return super.onOptionsItemSelected(item);
  }

  @Override public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_month_attendance_detail, container, false);
    findView(v);
    initData();
    return v;
  }

  private void findView(View v) {
    tvAttendyearMonth = (TextView) v.findViewById(R.id.tv_attendyearMonth);
    tvStaffName = (TextView) v.findViewById(R.id.tv_staffName);
    tvNaturalDays = (TextView) v.findViewById(R.id.tv_naturalDays);
    tvWorkDays = (TextView) v.findViewById(R.id.tv_workDays);
    tvPaidSalaryDays = (TextView) v.findViewById(R.id.tv_paidSalaryDays);
    tvRebackDescribe = (TextView) v.findViewById(R.id.tv_rebackDescribe);
    tvOnPositionDays = (TextView) v.findViewById(R.id.tv_onPositionDays);
    tvLunchFee = (TextView) v.findViewById(R.id.tv_lunchFee);
    tvPrivateDays = (TextView) v.findViewById(R.id.tv_privateDays);
    tvOtherDays = (TextView) v.findViewById(R.id.tv_otherDays);
    tvMaternityLeaveDays = (TextView) v.findViewById(R.id.tv_maternityLeaveDays);
    tvSickDays = (TextView) v.findViewById(R.id.tv_sickDays);
    tvPaidDays = (TextView) v.findViewById(R.id.tv_paidDays);
    tvLateTimes = (TextView) v.findViewById(R.id.tv_lateTimes);
    tvEarlierTimes = (TextView) v.findViewById(R.id.tv_earlierTimes);
    tvPunitiveDays = (TextView) v.findViewById(R.id.tv_punitiveDays);
    tvExtraDays = (TextView) v.findViewById(R.id.tv_extraDays);
    tvExtraPayDays = (TextView) v.findViewById(R.id.tv_extraPayDays);
    tvStatutoryHoliday = (TextView) v.findViewById(R.id.tv_statutoryHoliday);
    tvDeductionDays = (TextView) v.findViewById(R.id.tv_deductionDays);
    tvHandleDesc = (TextView) v.findViewById(R.id.tv_handleDesc);
    tvDataStatuse = (TextView) v.findViewById(R.id.tv_dataStatuse);
    tvRegisterName = (TextView) v.findViewById(R.id.tv_registerName);
    tvRegisterTime = (TextView) v.findViewById(R.id.tv_registerTime);
    tvCheckorName = (TextView) v.findViewById(R.id.tv_checkorName);
    tvCheckTime = (TextView) v.findViewById(R.id.tv_checkTime);
    tvApprManName = (TextView) v.findViewById(R.id.tv_apprManName);
    tvApprManTime = (TextView) v.findViewById(R.id.tv_ApprManTime);
    tvAbsenceDays = (TextView) v.findViewById(R.id.tv_absenceDays);
  }

  private void initData() {
    tvAttendyearMonth.setText(content.getAttendyearMonth());
    tvStaffName.setText(content.getStaffName());
    tvNaturalDays.setText(content.getNaturalDays());
    tvWorkDays.setText(content.getWorkDays());
    tvPaidSalaryDays.setText(content.getPaidSalaryDays());
    tvRebackDescribe.setText(content.getRebackDescribe());
    tvOnPositionDays.setText(content.getOnPositionDays());
    tvLunchFee.setText(content.getLunchFee());
    tvPrivateDays.setText(content.getPrivateDays());
    tvOtherDays.setText(content.getOtherDays());
    tvMaternityLeaveDays.setText(content.getMaternityLeaveDays());
    tvSickDays.setText(content.getSickDays());
    tvPaidDays.setText(content.getPaidDays());
    tvLateTimes.setText(content.getLateTimes());
    tvEarlierTimes.setText(content.getEarlierTimes());
    tvPunitiveDays.setText(content.getPunitiveDays());
    tvExtraDays.setText(content.getExtraDays());
    tvExtraPayDays.setText(content.getExtraPayDays());
    tvStatutoryHoliday.setText(content.getStatutoryHoliday());
    tvDeductionDays.setText(content.getDeductionDays());
    tvHandleDesc.setText(content.getHandleDesc());
    tvAbsenceDays.setText(content.getAbsenceDays());
    //        MyUtils.switchDataStutus(getActivity(),tvDataStatuse,content.getAttenddataStatus());

    String dataStatus = content.getAttenddataStatus();
    if (DataStatus.PUBLIS.equals(dataStatus)) {
      tvDataStatuse.setText(R.string.publish);
    } else if (DataStatus.NEW.equals(dataStatus)) {
      tvDataStatuse.setText(R.string.draft);
    } else if (DataStatus.SUBMIT.equals(dataStatus)) {
      tvDataStatuse.setText(R.string.waitCheck);
    } else if (DataStatus.NEWBACK.equals(dataStatus)) {
      tvDataStatuse.setText(R.string.removeCheck);// 返回修改
    } else if (DataStatus.ORGBACK.equals(dataStatus)) {
      tvDataStatuse.setText(DataStatus.getDataStatusName(DataStatus.ORGBACK));// 部门返回
    } else if (DataStatus.ORGPUBLISH.equals(dataStatus)) {
      tvDataStatuse.setText(DataStatus.getDataStatusName(DataStatus.ORGPUBLISH));// 部门通过
    } else if (DataStatus.ORGUNITBACK.equals(dataStatus)) {
      tvDataStatuse.setText(DataStatus.getDataStatusName(DataStatus.ORGUNITBACK));// 单位返回
    } else if (DataStatus.ORUNITPUBLISH.equals(dataStatus)) {
      tvDataStatuse.setText(DataStatus.getDataStatusName(DataStatus.ORUNITPUBLISH));// 单位通过
    } else if (DataStatus.PERSONCHECK.equals(dataStatus)) {
      tvDataStatuse.setText(DataStatus.getDataStatusName(DataStatus.PERSONCHECK));// 个人核查
    } else if (DataStatus.ARCHIVE.equals(dataStatus)) {
      tvDataStatuse.setText(DataStatus.getDataStatusName(DataStatus.ARCHIVE));// 已归档
    }
    tvRegisterName.setText(content.getAttendRegManName());//登记人
    tvRegisterTime.setText(content.getAttendRegTime());
    tvCheckorName.setText(content.getAttendCheckManName());
    tvCheckTime.setText(content.getAttendCheckTime());
    tvApprManName.setText(content.getAttendApprManName());
    tvApprManTime.setText(content.getAttendApprTime());
  }

  public static MonthAttendanceDetailFragment newInstance(
      MonthAttendanceOriginal.MonthAttendanceContent content) {

    Bundle args = new Bundle();
    args.putSerializable(EXTRA_VALUE, content);
    MonthAttendanceDetailFragment fragment = new MonthAttendanceDetailFragment();
    fragment.setArguments(args);
    return fragment;
  }
}
